<?php
/**
 * Prado Portal.
 *
 * @author Steen Rabol <steen.rabol@gmail.com>
 * @link http://www.pradoportal.dk/
 * @copyright Copyright &copy; 2006,2007,2008 Steen Rabol
 * @license http://www.pradoportal.dk
 * @version $Id: PortalToDoRecord.php 289 2008-11-14 05:34:40Z steen.rabol@gmail.com $
 */

Prado::using('Application.Common.Data.PortalActiveRecord');
Prado::using('Application.Common.Data.PortalUserRecord');
Prado::using('Application.Common.Data.PortalToDoHistoryRecord');

class PortalToDoRecord extends PortalActiveRecord
{
	const TABLE='tbltodo';

	public $id;
	public $title;
	public $description;
	public $created		= 0;
	public $deadline	= 0;
	public $priority	= 0;
	public $assignedto	= 0;
	public $createdby	= 0;
	public $status		= 1;
	Public $assignedby	= 0;

	private	$_assignedtoName	= null;

	public static function finder($className=__CLASS__)
	{
		return parent::finder($className);
	}

	public function getStatusTxt()
	{
		switch($this->status)
		{
			case 0: return Prado::localize('Closed'); break;
			case 1: return Prado::localize('Open'); break;
			default: return ''; break;
		}
	}

	public function getPriorityTxt()
	{
		switch($this->priority)
		{
			case 0: return Prado::localize('Low'); break;
			case 1: return Prado::localize('Normal'); break;
			case 2: return Prado::localize('High'); break;
			default: return ''; break;
		}
	}

	public function getAssignedToName()
	{
		if($this->_assignedtoName === null)
		{
			$u = PortalUserRecord::finder()->findByid($this->assignedto);
			if($u)
				$this->_assignedtoName = $u->name;
			else
				$this->_assignedtoName = Prado::localize('None');;
		}

		return $this->_assignedtoName;
	}

	public function onDelete($param)
	{
		PortalToDoHistoryRecord::finder()->deleteAllBytodoid($this->id);
		parent::onDelete($param);
	}
}
?>